<?php
/**
 * GoodsRegionJoinModel.php
 * Created by PhpStorm.
 * User: 江小波
 * Date: 2019/05/11
 * Time: 15:16
 */
namespace app\api\model;

use app\common\Singleton;
use think\Db;

class GoodsRegionJoinModel
{
    use Singleton;

    public function delByGoodsId($goods_id,$extend=[])
    {
        // 删除 goods_id 对应的所有数据
        return Db::name('goods_category_join')
            ->where('goods_id',$goods_id)
            ->delete();
    }

    public function batch($goods_id,$data,$extend=[])
    {
        $addAll = [];
        foreach($data as $v)
        {
            $addAll[] = [
                'goods_id'=>$goods_id,
                'region_id'=>$v,
                'create_ts'=>time()
            ];
        }
        return Db::name('goods_category_join')
            ->insertAll($addAll);
    }
}